package com.bandi.tharshesnows.persistence;

import android.content.Context;

public class PersistenceClient {

  private static PersistenceClient INSTANCE;

  private CountyDAO countyDAO;
  private LocalityDAO localityDAO;
  private SkirunDAO skirunDAO;

  private PersistenceClient(Context context) {
    Database database = new Database(context);
    countyDAO = new CountyDAO(database);
    localityDAO = new LocalityDAO(database);
    skirunDAO = new SkirunDAO(database);
  }

  public static void init(Context context) {
    if (INSTANCE == null) {
      INSTANCE = new PersistenceClient(context);
    }
  }

  public static PersistenceClient getInstance() {
    if (INSTANCE == null) {
      throw new IllegalStateException("PersistenceClient has not been initialized.");
    }
    return INSTANCE;
  }

  public CountyDAO getCountyDAO() {
    return countyDAO;
  }

  public LocalityDAO getLocalityDAO() {
    return localityDAO;
  }

  public SkirunDAO getSkirunDAO() {
    return skirunDAO;
  }

}
